<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>操作台</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<!--<link rel="stylesheet" type="text/css" href="css/app.css" />-->
		<style>
			.mui-card .mui-control-content {
				padding: 10px;
			}

			.mui-control-content {
				height: 150px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<!-- <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> -->
			<h1 class="mui-title">操作台</h1>
			<div class="mui-action-menu mui-icon  mui-pull-right">
				<button class="mui-btn mui-btn-primary" type="button" onclick="Record_Edit();"
					style="top:0px; line-height: 1;">新增</button>
				<button class="mui-btn mui-btn-primary" type="button" onclick="Record_Input();"
					style="top:0px; line-height: 1;">批量新增</button>
			</div>
		</header>
		<div class="mui-content">
			<div style="padding: 10px 10px;">
				<div id="divTab" class="mui-segmented-control">
					<!--
					 <a class="mui-control-item mui-active" href="#item1" >待办公文（8）</a>
					 -->
				</div>
			</div>
			<div id="divTabContent">
				<!--
				<div id="item1" class="mui-control-content mui-active">
				 <ul class="mui-table-view" id="ulUserList">					
					 <li class="mui-table-view-cell">
						<div class="mui-table">
							<div class="mui-table-cell mui-col-xs-10">
								<h4 class="mui-ellipsis">信息化推进办公室张彦合同付款信息化</h4>
								<h5>申请人：李四</h5>								
							</div>
							<div class="mui-table-cell mui-col-xs-2 mui-text-right">
								<span class="mui-h5">12:25</span>
							</div>
						</div>						
					 </li>
				 </ul>
				  -->
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="libs/lib.js"></script>
		<script>
			var defaultSiteId = "";

			mui.init({
				swipeBack: true //启用右滑关闭功能
			});

			(function($) {
				$('#scroll').scroll({
					indicators: true //是否显示滚动条
				});

				Site_List();
			})(mui);

			function Site_List() {
				var servicesType = localStorage.getItem('SERVICE_TYPE');
				var param = {
					Param:{
						ServicesType: servicesType
					}
				}
				Core.Post("Site/List", param, function(result, status) {
					if (result.errorMsg) {
						Core.Msg.Alert(result.errorMsg);
						return;
					}

					var list = result.data;
					var html = "",
						htmlContent = "";
					var defaultIndex = 0;
					var siteId = Core.Tool.GetUrlParam("siteId");
					if (siteId) {
						for (var i = 0; i < list.length; i++) {
							if (list[i].id == siteId) {
								defaultIndex = i;
								break;
							}
						}
					}

					for (var i = 0; i < list.length; i++) {
						if (i == defaultIndex) {
							html += "<a class='mui-control-item mui-active' id='tbl_" + list[i].id + "' href='#" + list[
								i].id + "'>" + list[i].name + "("+list[i].total+")</a>";
							htmlContent += " <div id='" + list[i].id +
								"' class='mui-control-content mui-active'><ul class='mui-table-view' id='ul" + list[i]
								.id + "' style='padding-bottom: 80px;'></ul></div> ";
							continue;
						}
						html += "<a class='mui-control-item' id='tbl_" + list[i].id + "' href='#" + list[i].id + "'>" +
							list[i].name + "("+list[i].total+")</a>";
						htmlContent += " <div id='" + list[i].id +
							"' class='mui-control-content'><ul class='mui-table-view' id='ul" + list[i].id +
							"' style='padding-bottom: 80px;'></ul></div> ";
					}
					document.getElementById("divTab").innerHTML = html;
					document.getElementById("divTabContent").innerHTML = htmlContent;

					for (var i = 0; i < list.length; i++) {
						document.getElementById("tbl_" + list[i].id).addEventListener('tap', function() {
							var id = this.id.replace("tbl_", "");
							Record_List(id);
						}, false);
					}
					
					if(list && list[defaultIndex])
						Record_List(list[defaultIndex].id)
				});
			}

			function Record_List(siteId) {
				defaultSiteId = siteId;

				var param = {
					Param: {
						SiteId: siteId
					}
				}
				Core.Post("Record/List", param, function(result, status) {
					if (result.errorMsg) {
						Core.Msg.Alert(result.errorMsg);
						return;
					}

					var list = result.data;
					var html = "";
					var today = Core.Tool.GetTodayDate();
					var user = Core.User.GetUser();
					for (var i = 0; i < list.length; i++) {
						if (user.isAdmin === 1)
							html +=
							" <li class='mui-table-view-cell' style='font-style: oblique;' onclick='Record_Edit(" + list[
								i].id + ")'> ";
						else
							html += " <li class='mui-table-view-cell' style='font-style: oblique;'> ";
						html += " 	<div class='mui-table'> ";
						html += " 		<div class='mui-table-cell mui-col-xs-8'> ";
						html += " 			<h4 class='mui-ellipsis'>" + list[i].tagtypeName + " - " + list[i].tagName +
							" &nbsp;<span class='mui-badge mui-badge-success' style='font-size: 24px;'>" + list[i]
							.dataValue + "</span> </h4>";
						html += " 				<h5>创建人：" + list[i].userName + "</h5>								 ";
						html += " 			</div> ";
						html += " 	<div class='mui-table-cell mui-col-xs-4 mui-text-right'> ";
						html += " 		<span class='mui-h5'>" + list[i].createTime.replace(today, "") + "</span> ";
						html += " 	</div> ";
						html += " </div>						 ";
						html += "</li> ";
					}
					document.getElementById("ul" + siteId).innerHTML = html;

				});
			}

			function Record_Edit(id) {
				window.location.href = "record_edit.html?siteId=" + defaultSiteId + "&id=" + id;
			}

			function Record_Input() {
				window.location.href = "record_input.html?siteId=" + defaultSiteId;
			}
		</script>

	</body>

</html>